package cn.tom.service.impl;

import cn.tom.entity.DevelopmentHistory;
import cn.tom.mapper.DevelopmentHistoryMapper;
import cn.tom.service.DevelopmentHistoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DevelopmentHistoryServiceImpl implements DevelopmentHistoryService {
    @Autowired
    DevelopmentHistoryMapper developmentHistoryMapper;

    /**
     * 发展历程 奇数查询
     */
    public List<DevelopmentHistory> findByOdd() {
        List<DevelopmentHistory> byOdd = developmentHistoryMapper.findByOdd();
        return byOdd;
    }

    /**
     * 发展历程 偶数查询
     */
    public List<DevelopmentHistory> findByEven() {
        List<DevelopmentHistory> byEven = developmentHistoryMapper.findByEven();
        return byEven;
    }

    /**
     * 发展历程 根据ID查询
     */
    public DevelopmentHistory findById(Integer id) {
        DevelopmentHistory developmentHistory = developmentHistoryMapper.selectById(id);
        return developmentHistory;
    }


    public DevelopmentHistory getById(Integer id) {
        LambdaQueryWrapper<DevelopmentHistory> lqw = Wrappers.lambdaQuery();
        lqw.eq(id != null, DevelopmentHistory::getId, id);
        return developmentHistoryMapper.getById(id);
    }

    /**
     * 添加一个发展历程
     */
    @Override
    public int add(DevelopmentHistory developmentHistory) {
        int i = developmentHistoryMapper.insert(developmentHistory);
        return i;
    }

    /**
     * 更新发展历程
     *
     * @param developmentHistory
     * @return
     */
    @Override
    public int update(DevelopmentHistory developmentHistory) {
        int i = developmentHistoryMapper.updateById(developmentHistory);
        return i;
    }

    /**
     * 删除一个发展历程
     *
     * @param developmentHistory
     * @return
     */
    @Override
    public int del(DevelopmentHistory developmentHistory) {
        int i = developmentHistoryMapper.deleteById(developmentHistory);
        return i;
    }
}
